#include <iostream>

using namespace std;

const int N = 110;
int n , m;
int x[N] , w[N] , v[N];
int dp[N];
int main()
{
    cin >> n >> m;
    for(int i = 1;i <= n;i ++) cin >> x[i] >> w[i] >> v[i];
    for(int i = 1;i <= n;i ++)
        for(int j = m;j >= 0;j --)
            for(int k = 0;k <= x[i] && k * w[i] <= j;k ++)
                dp[j] = max(dp[j] , dp[j-k*w[i]] + k * v[i]);

    cout << dp[m] << endl;
    return 0;
}